package gl.android.biyiqing.fragment;

import gl.adapter.SimpleAdapter.OnItemChildViewClick;
import gl.android.biyiqing.R;
import gl.android.biyiqing.api.API;
import gl.android.biyiqing.competent.OnLoveAskItemClickListener;
import gl.common.UserManger;

import org.json.JSONException;
import org.json.JSONObject;

import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ListView;
import android.widget.TextView;

public class LoveAskListFragment extends BaseListFragmet {

	private TextView empty;
	private ListView list;
	String NOTFOUND = "目前没有什么内容";
	private Drawable drawable;

	private void bindViews() {

		empty = (TextView) findViewById(R.id.empty);
		list = (ListView) findViewById(android.R.id.list);
		list.setEmptyView(empty);
		empty.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				initdata();
			}
		});

		empty.setText(NOTFOUND);

		empty.setCompoundDrawablesWithIntrinsicBounds(null, drawable, null,
				null);
	}

	public static LoveAskListFragment newInstance() {
		LoveAskListFragment fragment = new LoveAskListFragment();
		Bundle args = new Bundle();
		fragment.setArguments(args);
		return fragment;
	}

	public LoveAskListFragment() {
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		rootView = inflater.inflate(R.layout.listview_empty, container,
				false);
		drawable = getActivity().getResources().getDrawable(
				R.drawable.ic_discovery_pic_btn3);
		bindViews();
		initdata();
		return rootView;
	}

	private void initdata() {
		setListViewDividerHeight(4);
		initAbsListView(getListView(), API.URL + "GetAskList?userid=%s",
				new Object[] { UserManger.getInstance().userid },
				R.layout.item_list_love, new String[] { "title", 
						"content" }, new int[] { R.id.tv_nick, 
						R.id.age });

	}
	@Override
	protected OnItemChildViewClick getOnItemChildViewCilck() {
		return new OnLoveAskItemClickListener(getActivity(), dataJSONArray.toString());
	}
	@Override
	public Object getOnItemListener(String[] from, String t)
			throws JSONException {
		return new OnLoveAskItemClickListener(getActivity(), new JSONObject(t)
				.getJSONArray("data").toString());
		// 测试详情
	}

}